﻿using System;
using com.Bliss.Infrastructure;
namespace com.Bliss.Services
{
    public class UserService : IUserService
    {
        public TypedCollectionResponse<Bliss.User> GetUsers(int companyId)
        {
            
            var user = new Domain.User.User();
            try
            {
                var allUsers = user.GetUsers(companyId);
                return new TypedCollectionResponse<Bliss.User>(allUsers);
            }
            catch (Exception ex)
            {
                var data = new TypedCollectionResponse<Bliss.User>(null);
                data.HasErrors = true;
                data.errors = new string[] { ex.Message };
                return data;
            }
        }
        public TypedResponse<Bliss.User> GetUser(int userID)
        {
            var userDomain = new Domain.User.User();
            try
            {
                var user = userDomain.GetUser(userID);
                return new TypedResponse<Bliss.User>(user);
            }
            catch (Exception ex)
            {
                var data = new TypedResponse<Bliss.User>(null);
                data.HasErrors = true;
                data.errors = new string[] { ex.Message };
                return data;
            }
        }
        public TypedResponse<Bliss.User> ValidateUserLogin(string email, string password)
        {
            var userDomain = new Domain.User.User();
            try
            {
                var user = userDomain.ValidateUserLogin(email, password);
                return new TypedResponse<Bliss.User>(user);
            }
            catch (Exception ex)
            {
                var data = new TypedResponse<Bliss.User>(null);
                data.HasErrors = true;
                data.errors = new string[] { ex.Message };
                return data;
            }

        }
        public TypedCollectionResponse<com.Bliss.User> GetFriends(int userID, int companyId)
        {
            var user = new Domain.User.User();
            try
            {
                var allFriends = user.GetFriends(userID, companyId);
                return new TypedCollectionResponse<Bliss.User>(allFriends);
            }
            catch (Exception ex)
            {
                var data = new TypedCollectionResponse<Bliss.User>(null);
                data.HasErrors = true;
                data.errors = new string[] { ex.Message };
                return data;
            }
        }
        public bool IsUserInRole(int userId, string RoleName)
        {
            var user = new Domain.User.User();
            if (user.IsUserInRole(userId,RoleName))
            {
               return true;
            }
            else
            {
               return false;
            }
        }
        public void CreateGroup(int userId, string groupName, string Description)
        {
            if (groupName.Trim().Equals(string.Empty))
                return;
            var user = new Domain.User.User();
            try
            {
                user.CreateGroup(userId, groupName, Description);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
